package com.company.restaurant.service.session;

import io.netty.channel.ChannelHandlerContext;

/**
 * Description of class.
 * Created 3/26/14 5:55 PM
 *
 * @author andrey.rodin@playtech.com
 */

public class TcpClientSession {

    private ChannelHandlerContext channel;
    private String token;
    private long createDate;
    private long lastUpdate;
    private final SessionState state = new SessionState();

    public ChannelHandlerContext getChannel() {
        return channel;
    }

    public void setChannel(ChannelHandlerContext channel) {
        this.channel = channel;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public long getCreateDate() {
        return createDate;
    }

    public void setCreateDate(long createDate) {
        this.createDate = createDate;
    }

    public long getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(long lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public SessionState getState() {
        return state;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof TcpClientSession)) return false;

        TcpClientSession that = (TcpClientSession) o;

        if (createDate != that.createDate) return false;
        if (lastUpdate != that.lastUpdate) return false;
        if (!channel.equals(that.channel)) return false;
        if (!state.equals(that.state)) return false;
        if (!token.equals(that.token)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = channel.hashCode();
        result = 31 * result + token.hashCode();
        result = 31 * result + (int) (createDate ^ (createDate >>> 32));
        result = 31 * result + (int) (lastUpdate ^ (lastUpdate >>> 32));
        result = 31 * result + state.hashCode();
        return result;
    }
}
